﻿using HXDNB.DAL;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace HXDNB.CMS.Controllers
{
    public class MeunsController : BaseController
    {
        //栏目列表
        public ActionResult List(FormCollection Form, int index = 0)
        {
            MeunBLL Bll = new MeunBLL();
            List<Meun> list = new List<Meun>();
            Bll.GetALLSort(0, ref list);
            if (string.IsNullOrWhiteSpace(Form["name"]) == false)
            {
                list = list.Where(i => i.Name.Contains(Form["name"])).ToList();
            }
            ViewBag.PagList = list;
            return View(Form);
        }
        //栏目管理
        public ActionResult Info(int? id)
        {
            Meun info = new Meun();
            if (id != null)
            {
                MeunBLL Bll = new MeunBLL();
                info = Bll.Get((int)id);
            }
            return View(info);
        }
        //栏目管理
        [HttpPost]
        public ActionResult Info(Meun info)
        {
            MeunBLL Bll = new MeunBLL();
            ViewBag.Result = true;
            if (info.ID > 0)
            {
                ViewBag.Result = Bll.Edit(info);
            }
            else
            {
                ViewBag.Result = Bll.Add(info) > 0;
            }
            return View(info);
        }
        //栏目删除
        [HttpPost]
        public string DelMeun(string id = "")
        {
            MeunBLL Bll = new MeunBLL();
            bool result = true;
            foreach (string item in id.Split(','))
            {
                if (string.IsNullOrWhiteSpace(item) == false)
                {
                    result = Bll.Delete(int.Parse(item));
                    if (result == false)
                    {
                        break;
                    }
                }
            }
            return result.ToString();
        }
    }
}
